package com.abc.robot01.activity.compose

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.GenericShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Card
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SwipeToDismissBox
import androidx.compose.material3.SwipeToDismissBoxValue
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.zIndex
import androidx.wear.compose.material.Icon
import androidx.wear.compose.material.LocalContentAlpha
import com.abc.robot01.R
import com.abc.robot01.activity.AddQAActivity.Companion.TAG
import com.abc.robot01.activity.CustomStyledTextField20
import com.abc.robot01.activity.QuestionBean
import com.abc.robot01.activity.px
import kotlinx.coroutines.launch

class RowDemo : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            val scrollState = rememberScrollState()
            Row03()
//            Column(
//                modifier = Modifier
//                    .verticalScroll(scrollState)
//                    .fillMaxSize()
//            ) {
////                Row01()
////                Modifier03()
////                Modifier01()
//                Spacer(modifier = Modifier.height(2.dp))
//                ListDemo()
////                Row02()
////                ThemedScreen()
//                Spacer(modifier = Modifier.height(2.dp))
////                SlotApiExample()
//                Spacer(modifier = Modifier.height(2.dp))
//                Spacer(modifier = Modifier.height(2.dp))
//                Spacer(modifier = Modifier.height(2.dp))
//                Spacer(modifier = Modifier.height(2.dp))
//            }
        }
    }
}

@Composable
fun Row03() {
    Row(
        modifier = Modifier
            .width(800.dp)
            .background(
                color = Color.LightGray, shape = RoundedCornerShape(
                    12.dp
                )
            )
    ) {
        Text(
            text = "Fixed",
        )
        Spacer(modifier = Modifier.width(20.dp))
        Text(
            text = "Flexible",
        )
    }
}

@Composable
fun Row01() {
    Row(
        modifier = Modifier.fillMaxWidth()
    ) {
        Text(
            text = "Fixed",
            modifier = Modifier
                .width(100.dp)
                .background(Color.Red)
        )
        Text(
            text = "Flexible",
            modifier = Modifier
                .weight(1f)
                .background(Color.Blue)
        )
    }

}

@Composable
fun Row02() {
    Row(
        modifier = Modifier.fillMaxWidth(),
                horizontalArrangement = Arrangement.SpaceBetween
    ) {
        Text(
            text = "Fixed",
            modifier = Modifier
                .width(100.dp)
                .background(Color.Red)
        )
        Text(
            text = "Flexible",
            modifier = Modifier
                .width(100.dp)
                .background(Color.Blue)
        )
    }

}


@Composable
fun ListDemo() {
    val items = remember { mutableStateListOf("Item 1", "Item 2", "Item 3") }
    Column {
        LazyColumn {
            items(items) { item ->
                Text(
                    text = item,
                    modifier = Modifier
                        .fillMaxWidth()
                        .padding(8.dp)
                )
            }
        }
        // Button to add an item
        Button(onClick = {
            items.add("Item ${items.size + 1}")
        }) {
            Text("Add Item")
        }
        // Button to remove an item
        Button(onClick = {
            if (items.isNotEmpty()) {
                items.removeAt(items.size - 1)
            }
        }) {
            Text("Remove Last Item")
        }

        Button(onClick = {
            if (items.isNotEmpty()) {
                items[0]="123"
            }
        }) {
            Text("Update Item 0")
        }
    }
}


@Composable
fun ListDemo2() {
    val items = remember { mutableStateListOf(QuestionBean(question = "1"), QuestionBean(question = "2"),QuestionBean(question = "3")) }
    Column {
        LazyColumn {
            items(items) { item ->
                Text(
                    text = item.question,
                    modifier = Modifier
                        .fillMaxWidth()
                        .padding(8.dp)
                )
            }
        }
        // Button to add an item
        Button(onClick = {
            items.add(QuestionBean(question = "Item ${items.size + 1}"))
        }) {
            Text("Add Item")
        }
        // Button to remove an item
        Button(onClick = {
            if (items.isNotEmpty()) {
                items.removeAt(items.size - 1)
            }
        }) {
            Text("Remove Last Item")
        }

        Button(onClick = {
            if (items.isNotEmpty()) {
                items[0] = items[0].copy(question = "new value")
            }
        }) {
            Text("Update Item 0")
        }

        CustomStyledTextField20(text=items[0].question,placeHolder = "请输入", size= DpSize(560.px,50.px)){
            if (items.isNotEmpty()) {
                items[0] = items[0].copy(question = it)
            }
            Log.e(TAG," items[index] "+ items[0]);
        }

    }
}











